/*********************************************************
          File Name:forward_list.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 14 Sep 2015 09:12:35 PM CST
**********************************************************/

#include <iostream>
using namespace std;

#include <forward_list>

void show(forward_list<int> &fls)
{
        for(auto &x: fls)
                cout << x << " ";
        cout << endl;
}

int main()
{
        forward_list<int> fls;

        cout << unitbuf;

        for(int i = 1; i < 5; i++)
                fls.push_front(i);      
        // seems `forward_list` is a list with `head` node and the insert operation is 
        // like 
        //      node->next = head->next; 
        //      head = node;

        show(fls);

        fls.insert_after(fls.before_begin(), 309);
        show(fls);

        fls.emplace_after(fls.cbefore_begin(), 89);
        show(fls);

        fls.emplace_front(92);
        show(fls);

        fls.erase_after(fls.begin());   // `erase_after(fls.end())` casue seg fault
        show(fls);

        auto stop = fls.begin();
        stop++;
        fls.erase_after(fls.before_begin(), stop);
        show(fls);

        fls.clear();
        
        return 0;
}
